Public Member Functions | |
| __construct ($archiver, $recursion) | |
| setRecursion ($recursion) | |
| getRecursion () | |
| setArchiver ($archiver) | |
| getArchiver () | |
| visit (Resource $resource, $parentPath="") | |
Private Member Functions | |
| visitFolder (Folder $folder, $parentPath) | |
| visitFile (File $file, $parentPath) | |
| visitLink (File $file, $parentPath) | |
| addResourceDescription (Resource $resource, $path) | |
Private Attributes | |
| $recursion | |
| $archiver | |
Visitor implementation to move through Resource-Tree.
Definition at line 40 of file class.zipvisitor.inc.php.
| ZipVisitor::__construct | ( | $ | archiver, | |
| $ | recursion | |||
| ) |
Constructor of ArchiveVisitor.
Initialize Visitor with archive and recursion flag.
| unknown_type | $archiver | |
| unknown_type | $recursion |
Implements ResourceVisitor.
Definition at line 53 of file class.zipvisitor.inc.php.
References $archiver, and $recursion.
00053 { 00054 assert(!is_null($archiver)); 00055 assert($archiver instanceof ZipArchive); 00056 00057 $this->archiver = $archiver; 00058 $this->recursion = $recursion; 00059 }
| ZipVisitor::addResourceDescription | ( | Resource $ | resource, | |
| $ | path | |||
| ) | [private] |
Adding resource description as comment to the archive.
Definition at line 243 of file class.zipvisitor.inc.php.
References Resource::getDescription(), and Resource::getName().
Referenced by visitFile(), visitFolder(), and visitLink().
00243 { 00244 00245 $description = $resource->getDescription(); 00246 //$description = iconv ("windows-1251", "ASCII//TRANSLIT", $description); 00247 $description = iconv ("latin1", "ASCII//TRANSLIT", $description); 00248 00249 if (!$this->archiver->setCommentName($path, $description)) { 00250 throw new ArchiverException("Für die Ressource '".$resource->getName(). 00251 "' konnte kein Kommentar hinzugefügt werden"); 00252 } 00253 }
| ZipVisitor::getArchiver | ( | ) |
Getter for archiver.
Implements ResourceVisitor.
Definition at line 93 of file class.zipvisitor.inc.php.
| ZipVisitor::getRecursion | ( | ) |
Getter for recursion flag.
Implements ResourceVisitor.
Definition at line 75 of file class.zipvisitor.inc.php.
| ZipVisitor::setArchiver | ( | $ | archiver | ) |
Setter for archiver.
| unknown_type | $archiver archiver |
Implements ResourceVisitor.
Definition at line 84 of file class.zipvisitor.inc.php.
References $archiver.
00084 { 00085 $this->archiver = $archiver; 00086 }
| ZipVisitor::setRecursion | ( | $ | recursion | ) |
Setter for recursion flag.
| Boolean | $recursion Recursion flag. |
Implements ResourceVisitor.
Definition at line 66 of file class.zipvisitor.inc.php.
References $recursion.
00066 { 00067 $this->recursion = $recursion; 00068 }
| ZipVisitor::visit | ( | Resource $ | resource, | |
| $ | parentPath = "" | |||
| ) |
General visitor method for dipatching.
Dispatch the visitor invokation.
Implements ResourceVisitor.
Definition at line 105 of file class.zipvisitor.inc.php.
References visitFile(), visitFolder(), and visitLink().
00105 { 00106 assert(!is_null($resource)); 00107 00108 if ($resource instanceof Folder) { 00109 $this->visitFolder($resource, $parentPath); 00110 } elseif ($resource instanceof File) { 00111 if ($resource->getType() == "file") { 00112 $this->visitFile($resource, $parentPath); 00113 } elseif ($resource->getType() == "link") { 00114 $this->visitLink($resource, $parentPath); 00115 } else { 00116 throw new ArchiverException("Unbekannter Typ des 'File'-Objekts"); 00117 } 00118 } 00119 }
| ZipVisitor::visitFile | ( | File $ | file, | |
| $ | parentPath | |||
| ) | [private] |
Internal visitor to handle File resources.
Definition at line 175 of file class.zipvisitor.inc.php.
References addResourceDescription(), File::getExtension(), Resource::getName(), and File::getPathToFile().
Referenced by visit().
00175 { 00176 assert($file instanceof File); 00177 00178 $filePath = $parentPath.$file->getOrigFileName(); 00179 00180 $suffix = 0; 00181 while ($this->archiver->locateName($filePath, ZipArchive::FL_NOCASE) != FALSE) { 00182 if ($suffix == 0) { 00183 $pattern = ".".$file->getExtension()."$"; 00184 } else { 00185 $pattern = "-".$suffix.".".$file->getExtension()."$"; 00186 } 00187 $suffix++; 00188 $replacement = "-".$suffix.".".$file->getExtension(); 00189 00190 $filePath = ereg_replace($pattern, $replacement, $filePath); 00191 } 00192 00193 if (!$this->archiver->addFile($file->getPathToFile(), $filePath)) { 00194 throw new ArchiverException("Datei '".$file->getName(). 00195 "' konnte nicht zum Archiv hinzugefügt werden"); 00196 } 00197 00198 self::addResourceDescription($file, $filePath); 00199 }
| ZipVisitor::visitFolder | ( | Folder $ | folder, | |
| $ | parentPath | |||
| ) | [private] |
Internal visitor to handle Folder resources.
Definition at line 127 of file class.zipvisitor.inc.php.
References addResourceDescription(), Folder::getFiles(), Resource::getName(), and Folder::getSubFolders().
Referenced by visit().
00127 { 00128 assert($folder instanceof Folder); 00129 00130 00131 $path = $parentPath.$folder->getLink(); 00132 00133 $suffix = 0; 00134 while ($this->archiver->locateName($path, ZipArchive::FL_NOCASE) != FALSE) { 00135 if ($suffix == 0) { 00136 $pattern = "$"; 00137 } else { 00138 $pattern = "-".$suffix."$"; 00139 } 00140 $suffix++; 00141 $replacement = "-".$suffix; 00142 00143 $path = ereg_replace($pattern, $replacement, $filePath); 00144 } 00145 $path .= "/"; 00146 00147 if (!$this->archiver->addEmptyDir($path)) { 00148 throw new ArchiverException("Verzeichnis '".$folder->getName(). 00149 "' konnte nicht zum Archiv hinzugefügt werden"); 00150 } 00151 00152 $this->addResourceDescription($folder, $path); 00153 00154 $parentPath = $path; 00155 00156 if ($this->recursion) { 00157 $subFolders = $folder->getSubFolders(); 00158 foreach ($subFolders as $subFolder) { 00159 $subFolder->archiverAccept($this, $parentPath); 00160 } 00161 } 00162 00163 $files = $folder->getFiles(); 00164 foreach ($files as $file) { 00165 $file->archiverAccept($this, $parentPath); 00166 } 00167 }
| ZipVisitor::visitLink | ( | File $ | file, | |
| $ | parentPath | |||
| ) | [private] |
Internal visitor to handle Link resources.
Definition at line 207 of file class.zipvisitor.inc.php.
References addResourceDescription(), File::getExtension(), and Resource::getName().
Referenced by visit().
00207 { 00208 assert($file instanceof File); 00209 00210 $filePath = $parentPath.$file->getName().".url"; 00211 00212 $content = "[InternetShortcut]"; 00213 $content .= "\r\n"; 00214 $content .= "URL=".$file->getLink(); 00215 00216 $suffix = 0; 00217 while ($this->archiver->locateName($filePath, ZipArchive::FL_NOCASE) != FALSE) { 00218 if ($suffix == 0) { 00219 $pattern = ".".$file->getExtension()."$"; 00220 } else { 00221 $pattern = "-".$suffix.".".$file->getExtension()."$"; 00222 } 00223 $suffix++; 00224 $replacement = "-".$suffix.".".$file->getExtension(); 00225 00226 $filePath = ereg_replace($pattern, $replacement, $filePath); 00227 } 00228 00229 if (!$this->archiver->addFromString($filePath, $content)) { 00230 throw new ArchiverException("Datei '".$file->getName(). 00231 "' konnte nicht zum Archiv hinzugefügt werden"); 00232 } 00233 00234 $this->addResourceDescription($file, $filePath); 00235 }
ZipVisitor::$archiver [private] |
Definition at line 43 of file class.zipvisitor.inc.php.
Referenced by __construct(), and setArchiver().
ZipVisitor::$recursion [private] |
Definition at line 42 of file class.zipvisitor.inc.php.
Referenced by __construct(), and setRecursion().
1.6.1